package com.iter.devbox.util;

/**
 * 比较对象大小，实现Comparable接口
 * 
 * @author Jimly
 */
public class User implements Comparable<User> {
	
	/**用户年龄*/
	private int age;
	
	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public int compareTo(User u) {
		if (this.getAge() > u.getAge()) {
			return 1;
		} else if (this.getAge() == u.getAge()) {
			return 0;
		} else {
			return -1;
		}
	}
	
	public static void main(String[] args) {
		User u1 = new User();
		u1.setAge(20);
		
		User u2 = new User();
		u2.setAge(21);
		
		System.out.println(u1.compareTo(u2));
	}
}